package com.aim.config;

import javax.servlet.Filter;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

/**
 * @AUTO 初始化Spring，替代web.xml
 * @FILE WebApplicationInitializer.java
 * @DATE 2021年4月26日 下午2:31:37
 * @Author AIM
 * @Version
 */
public class WebApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

	@Override
	protected Class<?>[] getRootConfigClasses() {
		return new Class<?>[] { SpringRootConfig.class };
	}

	@Override
	protected Class<?>[] getServletConfigClasses() {
		return new Class<?>[] { SpringWebConfig.class };
	}

	// 映射根路径初始化
	@Override
	protected String[] getServletMappings() {
		return new String[] { "/" };
	}

	// 配置字符过滤器
	@Override
	protected Filter[] getServletFilters() {
		CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
		characterEncodingFilter.setEncoding("UTF-8");
		characterEncodingFilter.setForceEncoding(false);
		return new Filter[] { characterEncodingFilter };
	}
}
